package com.atwei.mango.system.securityHandler;

import com.atwei.mango.system.apiModel.response.ApiResponse;
import com.atwei.mango.system.exception.ResponseEnum;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Classname UserLogoutSuccessHandler
 * @Description 登出成功控制类
 * @Date 2022/6/9 15:59
 * @Author liuwei
 */
@Component
public class UserLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        SecurityContextHolder.clearContext();
        ApiResponse.responseJson(response,ApiResponse.info(ResponseEnum.LOGOUT_SUCCESS,null));
    }
}
